package com.jy.borrow.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jy.common.annotation.Log;
import com.jy.common.core.controller.BaseController;
import com.jy.common.core.domain.AjaxResult;
import com.jy.common.enums.BusinessType;
import com.jy.borrow.domain.Borrow;
import com.jy.borrow.service.IBorrowService;
import com.jy.common.utils.poi.ExcelUtil;
import com.jy.common.core.page.TableDataInfo;

/**
 * 图书借阅记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/borrow/borrow")
public class BorrowController extends BaseController
{
    @Autowired
    private IBorrowService borrowService;

    /**
     * 查询图书借阅记录列表
     */
    @PreAuthorize("@ss.hasPermi('borrow:borrow:list')")
    @GetMapping("/list")
    public TableDataInfo list(Borrow borrow)
    {
        startPage();
        List<Borrow> list = borrowService.selectBorrowList(borrow);
        return getDataTable(list);
    }

    /**
     * 导出图书借阅记录列表
     */
    @PreAuthorize("@ss.hasPermi('borrow:borrow:export')")
    @Log(title = "图书借阅记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Borrow borrow)
    {
        List<Borrow> list = borrowService.selectBorrowList(borrow);
        ExcelUtil<Borrow> util = new ExcelUtil<Borrow>(Borrow.class);
        util.exportExcel(response, list, "图书借阅记录数据");
    }

    /**
     * 获取图书借阅记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('borrow:borrow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(borrowService.selectBorrowById(id));
    }

    /**
     * 新增图书借阅记录
     */
    @PreAuthorize("@ss.hasPermi('borrow:borrow:add')")
    @Log(title = "图书借阅记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Borrow borrow)
    {
        return toAjax(borrowService.insertBorrow(borrow));
    }

    /**
     * 修改图书借阅记录
     */
    @PreAuthorize("@ss.hasPermi('borrow:borrow:edit')")
    @Log(title = "图书借阅记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Borrow borrow)
    {
        return toAjax(borrowService.updateBorrow(borrow));
    }

    /**
     * 删除图书借阅记录
     */
    @PreAuthorize("@ss.hasPermi('borrow:borrow:remove')")
    @Log(title = "图书借阅记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(borrowService.deleteBorrowByIds(ids));
    }
}
